package com.ehotting.edsta.circuitDesign.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ehotting.edsta.circuitDesign.Constants;
import com.ehotting.edsta.circuitDesign.domain.EsCircuitCodeData;
import com.ehotting.edsta.circuitDesign.domain.EsRuleScript;
import com.ehotting.edsta.circuitDesign.exception.LoggerAnnotation;
import com.ehotting.edsta.circuitDesign.service.IEsCircuitCodeDataService;
import com.ehotting.eaf.core.utils.poi.ExcelUtil;
import com.ehotting.eaf.core.web.controller.BaseController;
import com.ehotting.eaf.core.web.domain.AjaxResult;
import com.ehotting.eaf.core.web.page.TableDataInfo;
import com.ehotting.edsta.common.log.annotation.Log;
import com.ehotting.edsta.common.log.enums.BusinessType;
import com.ehotting.eaf.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 电路属性参数Controller
 * 
 * @author edsta
 * @date 2023-07-24
 */
@RestController
@RequestMapping("/codeData")
public class EsCircuitCodeDataController extends BaseController
{
    @Autowired
    private IEsCircuitCodeDataService esCircuitCodeDataService;

    /**
     * 查询电路属性参数列表
     */
//    @PreAuthorize(hasPermi = "edsta:data:list")
    @GetMapping("/list")
    public TableDataInfo list(EsCircuitCodeData esCircuitCodeData)
    {
        startPage();
        List<EsCircuitCodeData> list = esCircuitCodeDataService.selectEsCircuitCodeDataList(esCircuitCodeData);
        return getDataTable(list);
    }

    /**
     * 查询电路属性参数列表
     */
//    @PreAuthorize(hasPermi = "edsta:data:allList")
    @GetMapping("/allList")
    public AjaxResult allList(EsCircuitCodeData esCircuitCodeData)
    {
        List<EsCircuitCodeData> list = esCircuitCodeDataService.selectEsCircuitCodeDataList(esCircuitCodeData);
        return AjaxResult.success(list);
    }

    /**
     * 导出电路属性参数列表
     */
//    @PreAuthorize(hasPermi = "edsta:data:export")
    @Log(title = "电路属性参数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EsCircuitCodeData esCircuitCodeData) throws IOException
    {
        List<EsCircuitCodeData> list = esCircuitCodeDataService.selectEsCircuitCodeDataList(esCircuitCodeData);
        ExcelUtil<EsCircuitCodeData> util = new ExcelUtil<EsCircuitCodeData>(EsCircuitCodeData.class);
        util.exportExcel(response, list, "电路属性参数数据");
    }

    /**
     * 获取电路属性参数详细信息
     */
//    @PreAuthorize(hasPermi = "edsta:data:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(esCircuitCodeDataService.selectEsCircuitCodeDataById(id));
    }

    /**
     * 新增电路属性参数
     */
//    @PreAuthorize(hasPermi = "edsta:data:add")
    @Log(title = "电路属性参数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EsCircuitCodeData esCircuitCodeData)
    {
        return toAjax(esCircuitCodeDataService.insertEsCircuitCodeData(esCircuitCodeData));
    }

    /**
     * 修改电路属性参数
     */
//    @PreAuthorize(hasPermi = "edsta:data:edit")
    @Log(title = "电路属性参数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EsCircuitCodeData esCircuitCodeData)
    {
        return toAjax(esCircuitCodeDataService.updateEsCircuitCodeData(esCircuitCodeData));
    }

    /**
     * 删除电路属性参数
     */
//    @PreAuthorize(hasPermi = "edsta:data:remove")
    @Log(title = "电路属性参数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(esCircuitCodeDataService.deleteEsCircuitCodeDataByIds(ids));
    }


    /**
     * 新增电路属性参数
     */
//    @PreAuthorize(hasPermi = "edsta:data:addAll")
    @Log(title = "电路属性参数", businessType = BusinessType.INSERT)
    @PostMapping("addAll")
    public AjaxResult addAll(@RequestBody List<EsCircuitCodeData> esCircuitCodeDataList)
    {

        for (EsCircuitCodeData esCircuitCodeData : esCircuitCodeDataList){
            if (esCircuitCodeData.getId() != null){
                esCircuitCodeDataService.updateEsCircuitCodeData(esCircuitCodeData);
            }else {
                esCircuitCodeDataService.insertEsCircuitCodeData(esCircuitCodeData);
            }

        }

        return toAjax(true);
    }

}
